/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2010-5-24 下午09:14:48
 */
package com.filesystem;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @author Administrator
 * 
 */
public class FolderTraversal {

	public static String windPath = "\\\\10.0.2.115\\导出数据\\wind";
	public static String properties = "c:/basedayGroups.properties";
	public int totalBaseDay = 0 ;

	public void exportWindFile(String windPath) {

		try {
			
			FileOutputStream bw = null;
			File properFile = new File(properties);
			if (!properFile.exists())
			{
				properFile.createNewFile();
				bw = new FileOutputStream(properties);
			}else
				bw = new FileOutputStream(properties, true);

			File windFile = new File(windPath);
			File[] fileDirs = windFile.listFiles();

			String filePaths = "c:/server/";
			String strFileName = "";
			
			for (int i = 0; i < fileDirs.length; i++) {

				if (fileDirs[i].isDirectory())
					exportWindFile(fileDirs[i].getPath());
				else {
					strFileName = (fileDirs[i].getName().toLowerCase()).replaceAll(".xls", "");

					bw.write(("category_dirs_" + totalBaseDay + "=" + strFileName + "\r\n").getBytes());
					bw.write(("sample_size_" + totalBaseDay + "=30,60" + "\r\n\r\n").getBytes());

					System.out.println(strFileName);
					
					File sf = new File(filePaths + strFileName + "/wind/");
					if (!sf.exists())
						sf.mkdirs();

					FileInputStream fis = new FileInputStream(fileDirs[i].getCanonicalPath());
					FileOutputStream fos = new FileOutputStream(filePaths + strFileName + "/wind/" + strFileName + ".xls");

					byte[] buff = new byte[1024];
					int readed = -1;
					while ((readed = fis.read(buff)) > 0)
						fos.write(buff, 0, readed);
					fis.close();
					fos.close();
					
					totalBaseDay++ ;
				}
			}

			bw.flush();
			bw.close();

		} catch (Exception e) {

			e.printStackTrace();
		}

	}

	public static void main(String[] args) {

		FolderTraversal ft = new FolderTraversal() ;
		ft.exportWindFile(windPath);
	}

}
